<?php
## include required files
/*******************************/
require_once '../../includefiles.php';
require_once '../../model/trade.php';
include_once("../../model/users.php");
require_once '../../model/state.php';
require_once '../../redirect.php';
require_once '../../model/nab.php';
## Create Objects
/*******************************/
$objTrade = new Model_TRADE();
$userObj = new Model_Users();
$stateObj = new Model_State();
$NABObj = new Model_NAB();
$nab = $NABObj->getDetail();
/*******************************/
$allsubcats = $objTrade->getAllSubcats();

checkUserLogin();


if($_SESSION['user_type'] == '3')
{
	@header("location:".SITE_URL."/");
	exit;
}


if($_POST['subcat'] && $_POST['traderemove'] )
{
	if($_POST['traderemove'])
	{
		$removecats = $_POST['subcat'];
		$cats = $_SESSION['cats']['ids'];
		$remaincats = array();
		foreach($cats as $cat)
		{
			if(!in_array($cat,$removecats))
				$remaincats[] = $cat;	
		}
		if($remaincats)
		{
			$newcats = array();
			foreach($allsubcats as $pc)
			{	
				
				foreach($pc['data'] as $cc)
				{
					if(in_array($cc['id'],$remaincats))		
					{
						$cc['jobtype']	= $pc['trade_category'];
						$subtotal +=$cc['price'];
						$newcats[] = $cc;	
					}
				}
			}	
			$_SESSION['cats']['list'] = $newcats;
			$_SESSION['cats']['subtotal'] = $subtotal;
			$_SESSION['cats']['ids'] = $remaincats;
		}
		else		
		{
			@header("location:".SITE_URL."/myaccount/myservicelocation/");
			exit;	
		}
		
	}	
}
else
{
	$cats = $_POST['subcat'];
	$subtotal = 0;
	$newcats = array();
	if($cats)
	{
		foreach($allsubcats as $pc)
		{	
			
			foreach($pc['data'] as $cc)
			{
				if(in_array($cc['id'],$cats))		
				{
					$cc['jobtype']	= $pc['trade_category'];
					$subtotal +=$cc['price'];
					$newcats[] = $cc;	
				}
			}
		}	
		$_SESSION['cats']['list'] = $newcats;
		$_SESSION['cats']['subtotal'] = $subtotal;
		$_SESSION['cats']['ids'] = $cats;
	}
}
if(!$_SESSION['cats']['list'] || !$_SESSION['cats']['subtotal'])
{
	@header("location:".SITE_URL."/myaccount/myservicelocation/");
	exit;
}

$smarty->assign('subcats',$_SESSION['cats']['list']);
$smarty->assign('subtotal',number_format($_SESSION['cats']['subtotal'],2));
$active = "myaccount";
$smarty->assign("active", $active);
$subactive ="myservicelocation";
$smarty->assign("subactive", $subactive);
$smarty->assign('mainmenu', '3');
$smarty->assign('serviceslist', '1');

$smarty->display(TEMPLATEDIR . '/modules/myaccount/servicesconfirm.tpl');
?>